
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        picPath: app.globalData.path,
        answer: {},
        proInfo: {},
        answerList: '',
        metoAsk: '', //回答标识
    },
    // 获取详情
    getDetail() {
        wx.showLoading({
            title: '加载中',
        })
        var that = this
        var url = app.globalData.url + "product/getAnswerAndReply",
            data = {
                answerId: that.data.answer.answerId,
            };
        app.wxRequest(url, data, res => {
            if (res.flag) {
                wx.hideLoading()

                res.data.replyList.forEach(item => {
                    item.imgError = false
                    item.errimg = '/img/avatar.png'
                })
                console.log(res.data);
                that.setData({
                    answerList: res.data.replyList,
                })
            }
        })
    },

    imgErrHandle(e) {
        console.log(e);
        var index = e.currentTarget.dataset.index, list = this.data.answerList;
        list[index].imgError = true
        this.setData({
            answerList: list
        })
    },

    imgErrHandleAnswer() {
        var obj = this.data.answer
        obj.isError = true
        this.setData({
            answer: obj
        })
    },


    // 回答
    toReply() {
        var str = JSON.stringify(this.data.proInfo)
        var str1 = JSON.stringify(this.data.answer)
        console.log(str1);
        wx.navigateTo({
            url: '/packageProduct/pages/answerReply/answerReply?pro=' + str + '&str=' + str1
        })


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options);
        var answer = JSON.parse(options.str)
        answer.isError = false
        answer.errorimg = '/img/avatar.png'
        this.setData({
            answer: answer,
            proInfo: JSON.parse(options.pro)
        })
        console.log(this.data)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

        this.getDetail()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})